package keeper.control;

import javax.servlet.http.HttpServlet;

import keeper.event.Event;
import keeper.event.EventListener;
import keeper.util.NameRegister;
import keeper.util.RegistException;
/**
 * 
 * @author hliang@126.com
 *
 */
public class Controller {
	public static boolean action(EventListener listener,String eventName){
		NameRegister reg = NameRegister.getInstance();
		HttpServlet servlet = null;
		Event e = null;
		try {
			e = reg.getEvent(eventName,true);
			if(e == null) {
				return false;
			}
			e.setListener(listener);
			servlet = e.getServlet();
			e.setProcess(true);
			synchronized(servlet) {
				servlet.notifyAll();
			}
		} catch (RegistException ex) {
			ex.printStackTrace();
			}
		if(servlet != null && e != null) {
			e = null;
			return true;
		} else {
			return false;
		}
	}
}
